package controller;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import model.CTPhieuNhap;
import model.CTPhieuXuat;
import model.KhachHang;

public class CTPhieuXuatController {

	public static List<CTPhieuXuat> getListCtpx(int idpx) {
		Connection conn = DBConection.MYSQL;
		if (conn == null)
			return null;
		try {

			Statement stmt = conn.createStatement();
			String sql = "SELECT * FROM cthdxuat WHERE idhdx=" + idpx + ";";
			ResultSet rs = stmt.executeQuery(sql);
			CTPhieuXuat px;
			List<CTPhieuXuat> list = new ArrayList<>();
			while (rs.next()) {
				px = new CTPhieuXuat();
				px.setMaHDPX(idpx);
				px.setidMatHang(rs.getInt("mamh"));
				px.setSoLuong(rs.getInt("soluong"));
				// MatHangController m = new MatHangController();
				// int id = rs.getInt("mamh");

				list.add(px);

			}
			return list;
		} catch (Exception e) {
			e.printStackTrace();

			return null;
		}
	}

	public static void insertCTPhieuXuat(CTPhieuXuat px) {
		try {
			Statement sta = DBConection.MYSQL.createStatement();
			String query = "INSERT INTO cthdxuat (idhdx,mamh,soluong) VALUES (";
			query += "'" + px.getMaHDPX() + "',";
			query += "'" + px.getidMatHang() + "',";
			query += "'" + px.getSoLuong();
			query += "')";
			System.out.println(query);
			sta.execute(query);
			return;

		} catch (Exception e) {

			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		CTPhieuXuatController c = new CTPhieuXuatController();
		System.out.println(c.getListCtpx(1));
	}
}